﻿namespace SolidMvvm {
	using System;

	using SolidMvvmInterfaces;

	public abstract class LoggerBase : ModelBase, ILogger {
		protected LoggerBase(string filePathWithFileExtension) {
			FilePathWithFileExtension = filePathWithFileExtension;
		}

		public override void Dispose() {
			FilePathWithFileExtension = null;
			base.Dispose();
		}

		public abstract void AddMessage(string publicMessage, string privateMessageOrNull);

		public abstract string GetLogFileAsString();

		/// <summary>
		///     This will return whichever log file is used for the given time frame.
		/// </summary>
		public string GetLogFilePath(DateTime anyTime) {
			return FilePathWithFileExtension + anyTime.ToString("yyyy-MM");
		}

		public string FilePathWithFileExtension { get; private set; }

		protected static string GetCSVedString(string original) {
			const string crlfSubstitute = " <CRLF> ";

			return original.Replace("\"", "\"\"").Replace("\r\n", crlfSubstitute).Replace("\r", crlfSubstitute).Replace("\n", crlfSubstitute);
		}
	}
}
